/**
 * 
 */
package Client.View;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Observable;
import java.util.Observer;

import javax.swing.JButton;
import javax.swing.JPanel;

import utils.ImagePanel;
import Client.Model.GameModel;

/**
 * @author Rodrigo
 * 
 */

@SuppressWarnings("serial")
public class GameView extends JPanel implements Observer{
	
	private GameModel model;
	
	private int height;
	private int width;
	
	private JButton quitBtn;
	private JPanel topPanel, gamePanel, gamePlayPanel, gameConfigPanel, logoPanel;
	
	public GameView(GameModel m, int height, int width) {
		this.model = m;
		
		model.addObserver(this);
		
		this.height = height;
		this.width = width;
		
		setBounds(0,0,width,height);
		
		setView();
		setListeners();
		
	}
	
	@Override
	public void update(Observable arg0, Object arg1) {
		if (model.getView()==GameModel.VIEW_GAME)
			this.setVisible(true);
		else
			this.setVisible(false);
		
		revalidate();
		repaint();
		
	}
	
	private void setView(){
		
		this.setBackground(new Color(0,0,0,0));
		this.setLayout(new BorderLayout());
		
		this.setLayout(null);
		topPanel = new JPanel();
		gamePanel = new JPanel();
		logoPanel = new JPanel();
			
		this.add(topPanel);
		this.add(gamePanel);
		
		topPanel.setBackground(LoginFrame.DEFAULT_BG_COLOR);	
		topPanel.setBounds(0, 0, width, 100);
		
		gamePanel.setBounds(0, 100, width, height-100);
		gamePanel.setBackground(LoginFrame.DEFAULT_BG_COLOR);
		
		
		/*-- top panel --*/
		quitBtn = new JButton("Quit");
		
		logoPanel.setBackground(LoginFrame.DEFAULT_BG_COLOR);
		logoPanel.add(new ImagePanel("C:\\Users\\Rodrigo\\Dropbox\\Trabalhos\\PDist\\Partilha PDist\\logo.png", 0));
		topPanel.add(logoPanel);
		
		
		topPanel.add(quitBtn);
		
		
		/*-- game panel--*/
		gamePanel.setMinimumSize(new Dimension(width, height-50));
		gamePanel.setPreferredSize(new Dimension(width, height-50));
		
		gamePlayPanel = new GameConfigView(model, width, height-50);
		gameConfigPanel = new GamePlayView(model, width, height-50);
		
		gamePanel.add(gamePlayPanel);
		gamePanel.add(gameConfigPanel);
		
		
		
	}
	
	private void setListeners(){ 
		
		quitBtn.addMouseListener(new MouseAdapter() {
		
			@Override
			public void mousePressed(MouseEvent e) {
				model.quit();
			}
		
		});
	
				
	}
}
